package cn.magic.system.controller;

import cn.magic.basic.annotation.PreAuthorize;
import cn.magic.basic.utils.AjaxResult;
import cn.magic.basic.utils.PageList;
import cn.magic.system.domain.SystemDictionaryDetail;

import cn.magic.system.query.SystemDictionaryDetailQuery;

import cn.magic.system.service.ISystemDictionaryDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/detail")
@Api(value = "数据字典明细的API",description="数据字典明细的CRUD功能")
public class SystemDictionaryDetailController {

    @Autowired
    private ISystemDictionaryDetailService systemDictionaryDetailService;


    /**
     * @Title: loadById
     * @Description: 通过id查询
     * @Author: Mr.pc
     * @Version: 1.0
     * @Date:  2022/6/24 10:00
     * @Parameters: [id]
     * @Return cn.magic.org.domain.Employee
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询" )
    public cn.magic.system.domain.SystemDictionaryDetail loadById(@ApiParam(value="部门ID主键",required = true) @PathVariable("id") Long id){
        return systemDictionaryDetailService.loadById(id);

    }

    /**
     * @Title: loadAll
     * @Description: 查询所有
     * @Author: Mr.pc
     * @Version: 1.0
     * @Date:  2022/6/24 10:02
     * @Parameters: []
     * @Return java.util.List<cn.magic.org.domain.Employee>
     */
    @GetMapping
    @ApiOperation(value = "查询所有" )
    public List<SystemDictionaryDetail> loadAll(){
        return systemDictionaryDetailService.loadAll();
    }

    /**
     * @Title: remove
     * @Description: 通过id删除
     * @Author: Mr.pc
     * @Version: 1.0
     * @Date:  2022/6/24 11:06
     * @Parameters: [id]
     * @Return cn.magic.basic.utils.AjaxResult
     */
    @DeleteMapping("{id}")
    @ApiOperation(value = "通过ID删除" )
    @PreAuthorize(name = "删除数据字典明细", sn = "systemDictionaryDetail:delete")
    public AjaxResult remove(@ApiParam(value="部门ID主键",required = true) @PathVariable("id") Long id){
        try {
            systemDictionaryDetailService.remove(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试！！");
        }
    }

    /**
     * @Title: addOrUpt
     * @Description: 新增/修改
     * @Author: Mr.pc
     * @Version: 1.0
     * @Date:  2022/6/24 11:49
     * @Parameters: [employee]
     * @Return cn.magic.basic.utils.AjaxResult
     */
    @PutMapping
    @ApiOperation(value = "新增或者修改" )
    @PreAuthorize(name = "保存修改数据字典明细", sn = "systemDictionaryDetail:saveOrUpt")
    public AjaxResult addOrUpt(@ApiParam(value="部门新增或者修改的对象",required = true)@RequestBody SystemDictionaryDetail systemDictionaryDetail){
        try {
            if (systemDictionaryDetail.getId() == null){
                systemDictionaryDetailService.save(systemDictionaryDetail);
            } else{
                systemDictionaryDetailService.update(systemDictionaryDetail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试！！");
        }
    }

    /**
     * @Title: queryData
     * @Description: 高级查询和分页
     * @Author: Mr.pc
     * @Version: 1.0
     * @Date:  2022/6/24 11:57
     * @Parameters: [employeeQuery]
     * @Return cn.magic.basic.utils.PageList<cn.magic.org.domain.Employee>
     */
    @ApiOperation(value = "高级查询和分页查询" )
    @PostMapping
    @PreAuthorize(name = "列表数据字典明细", sn = "systemDictionaryDetail:list")
    public PageList<SystemDictionaryDetail> queryData(@ApiParam(value="高级查询和分页的对象",required = true)@RequestBody SystemDictionaryDetailQuery systemDictionaryDetailQuery){
        PageList<SystemDictionaryDetail> data = systemDictionaryDetailService.queryData(systemDictionaryDetailQuery);
        return data;

    }


    /**
     * @Title: batchDel
     * @Description: 批量删除
     * @Author: Mr.pc
     * @Version: 1.0
     * @Date:  2022/6/25 11:08
     * @Parameters: [ids]
     * @Return cn.magic.basic.utils.AjaxResult
     */
    @PatchMapping
    @PreAuthorize(name = "批量删除数据字典明细", sn = "systemDictionaryDetail:bulkRemove")
    public AjaxResult batchDel(@RequestBody Long[] ids){
        try {
            systemDictionaryDetailService.batchDel(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试！！");
        }
    }


}
